<?php
/**
 * 管理员相关（无需鉴权部分）
 * 
 * @author ShuangYa
 * @package APIGateway
 * @category Controller
 * @link https://www.sylingd.com/
 * @copyright Copyright (c) 2018 ShuangYa
 * @license https://www.sylibs.com/go/apigateway/license
 */
namespace ag\controller\admin;

use yesf\library\ControllerAbstract;

use ag\library\Utils;
use ag\model\Config;

class Index extends ControllerAbstract {
	//首页
	public static function indexAction($request, $response) {
		$response->display('index/index');
	}
	/**
	 * 登录
	 * 
	 * @api {post} /admin/index/login 登录
	 * @apiName Login
	 * @apiGroup Admin
	 * 
	 * @apiParam {String} password 密码
	 * 
	 * @apiSuccess {Boolean} success 是否成功
	 * @apiSuccess {String} error 失败原因
	 */
	public static function loginAction($request, $response) {
		$response->header('Content-Type', 'application/json; charset=UTF-8');
		$password = $request->post['password'];
		$encrypt = hash('sha256', $password);
		if ($encrypt === Config::getInstance()->read('admin_password')) {
			$response->write(Utils::getWebApiResult([
				'password' => $encrypt
			]));
		} else {
			$response->write(Utils::getWebApiResult([
				'error' => '密码错误'
			]));
		}
	}
}